package com.atguigu.ssyx.home.controller;


import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.common.security.AuthContextHolder;

import com.atguigu.ssyx.home.service.HomeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@Api(tags = "首页接口")
@RequestMapping("/api/home")
@RequiredArgsConstructor
public class HomeApiController {
    private final HomeService homeService;


    @ApiOperation(value = "获取首页数据")
    @GetMapping("/index")
    public Result index(HttpServletRequest request) {
        // 获取用户Id
        Long userId = AuthContextHolder.getUserId();
        Map<String, Object> map = homeService.home(userId);
        return Result.ok(map);
    }
}
